package models

type InterPushUserInfo struct {
	ID           int `gorm:"primary_key"json:"id"`
	UserId       int `json:"user_id"`
	MeProvinceId int `json:"me_province_id"`
	IsEnabled int `json:"is_enabled"`
}


func (m *InterPushUserInfo) TableName() string {
	return "interpush_user_info"
}

func (i *InterPushUserInfo) GetLastId() (*InterPushUserInfo, error) {
	var in InterPushUserInfo

	err := DB.Model(i).Select("id").Order("id desc").Limit("1").Find(&in).Error
	if err != nil {
		return nil, err
	}
	return &in, nil
}

func (i *InterPushUserInfo) Get() (*InterPushUserInfo, error) {
	var in InterPushUserInfo

	err := DB.Model(i).Where("id = ? and is_enabled = ? and weixin_img != ''", i.ID, i.IsEnabled).Find(&in).Error
	if err != nil {
		return nil, err
	}
	return &in, nil
}